package com.framework.spring.context.bfpp;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;

@Component
@Slf4j(topic = "e")
public class I implements BeanDefinitionRegistryPostProcessor, PriorityOrdered {

	public I() {
		log.info("I construct");
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		log.info("scan I#BeanFactoryPostProcessor.postProcessBeanFactory,PriorityOrdered");
	}

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		log.info("scan I#BeanFactoryPostProcessor.postProcessBeanDefinitionRegistry,PriorityOrdered");
//		// 此时 x中的@Bean没有生效
//		AbstractBeanDefinition xBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(X.class).getBeanDefinition();
//		registry.registerBeanDefinition("x", xBeanDefinition);
//		// 有PriorityOrdered支撑，执行时机正确，能回调L
//		AbstractBeanDefinition jBeanDefinition = (AbstractBeanDefinition) registry.getBeanDefinition("j");
//		jBeanDefinition.setBeanClass(L.class);
	}

	@Override
	public int getOrder() {
		log.info("I#PriorityOrdered.getOrder");
		return 2;
	}


}
